package com.xwdeshj.utils;
/**
 * @author yuxy
 * @date 2015/06/02
 * @mark ip获取
 */

import javax.servlet.http.HttpServletRequest;


public class IpUntil {
	/**
	 * 获取客户端IP地址
	 * @param request
	 * @return
	 */
	public static String returnIp(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		if(ip.equals("0:0:0:0:0:0:0:1")){
			ip = "127.0.0.1";
		}
		return ip;
	}
}
